package javaJob.exercise.primary.string;

/**
 * @Author: Jason
 * @ClassName: primary18
 * @Description: 外观数列
 * @Package：javaJob.exercise.primary.string
 * @Project：javaDemo
 * @name：primary18
 * @Filename：primary18
 **/

public class primary18 {

    public static void main(String[] args) {
        int n = 3;
        int nn=1211;

        System.out.println( countAndSay(5));


    }


    static String countAndSay(int n){
        int count=1;
        String number = "";
        if (n==1){
            System.out.println("n==1");
            return "1";
        }else if (n==2){
            System.out.println("n==2");
            return "11";
        }else {
            System.out.println("n:"+n);
            char[] target = countAndSay(n-1).toCharArray();
            System.out.println("target:"+target.length);
            for (int i=1;i<=target.length-1;i++){
                if (target[i-1]==target[i]){
                    count=count+1;
                    if (i+1==target.length){
                        number=number+count+target[i-1];
                        count=1;
                        System.out.println("i+1==target.length:"+number);
                    }
                }else if (target[i-1]!=target[i]){
                    number=number+count+target[i-1];
                    count=1;
                    if (i+1==target.length){
                        number=number+count+target[i];
                    }
                    System.out.println("target[i-1]!=target[i]:"+number);
                }
                System.out.println("i:"+i+" target:"+target[i]+" target.length:"+target.length);
            }
            System.out.println("number:"+number);
        }
//        if (n==1){
//            number=number+1;
//        }
//        for (int i=1;i<=target.length-1;i++){
//            if (target[i-1]==target[i]){
//                count=count+1;
//                if (i+1==target.length){
//                    number=number+count+target[i-1];
//                    count=1;
//                }
//            }else if (target[i-1]!=target[i]){
//                number=number+count+target[i-1];
//                count=1;
//            }
//            System.out.println("i:"+i+"target:"+target[i]);
//        }
//
//        System.out.println(number);
        return number;
    }

}

